package leetcode.editor.cn.q0xx

class Q58 {
    fun lengthOfLastWord(s: String): Int {
        var length = 0
        var hasWord = false
        for (i in s.indices.reversed()) {

            if (s[i] != ' ') {
                if (!hasWord)
                    hasWord = true
                length++
            } else if (hasWord && s[i]==' ')
                break
        }
        return length
    }
}